/*
 * RSAPubKeyMethod.cpp
 *
 *   Created on: 2010-3-28     
 *  Description: 
 *    Copyright: 2010 @ ICT Li Heyuan
 */

#include "../../include/method/RSAPubKeyMethod.h"
#include "../../include/util/Util.h"

bool RSAPubKeyMethod::execute_logic(Value &param, Value& result,
		const EasyAddr &addr, string &error)
{
	RSATools *rsa = Util::getInstance()->getRSAToolsByIP(addr.ip);
	if (rsa == NULL)//没有,生成RSA对
	{
		rsa = Util::getInstance()->generateRSAToolsByIP(addr.ip);
		if (rsa == NULL)
		{
			//内存分配出错
			return false;
		}
	}

	//组成n e的字符串
	string ret = rsa->getPublicExponent();
	ret.append("\t");
	ret.append(rsa->getModulus());
	delete rsa;

	//写入返回值
	result = Value(ret);

	return true;
}
